/**  
 * All rights Reserved, Designed By www.woniuxy.com
 * @Title:  Account.java   
 * @Package com.woniu.domain   
 * @Description:    Description  
 * @author: 蜗牛学院  
 * @date:   2019年7月31日 下午3:56:40
 * @user:   Administrator  
 * @version V1.0 
 * @Copyright: 2019 www.woniuxy.com Inc. All rights reserved. 
 * 注意：本内容仅限于成都蜗牛创想科技有限公司，禁止外泄以及用于其他的商业目
 */ 
package com.woniu.dao.impl;

import java.sql.SQLException;
import java.util.List;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;
import org.apache.commons.dbutils.handlers.ScalarHandler;

import com.woniu.dao.CategoryDao;
import com.woniu.domain.Category;
import com.woniu.domain.Goods;
import com.woniu.utils.DataSourceUtils;

/**
 * @author Administrator
 *
 */
public class CategoryDaoImpl implements CategoryDao {
private QueryRunner runner = new QueryRunner(DataSourceUtils.getDataSource());
	@Override
	public List<Category> getCategoryInfo() throws SQLException {
		return runner.query("select id,categoryimgpath,cname,productdescription from categoryinfo", new BeanListHandler<Category>(Category.class));
	}
	@Override
	public List<Goods> listGoodsByCategory(Integer cId, Integer currentPage, int pageSize) throws SQLException {
		
		return runner.query("select gid,goodimgpath,price,addimgpath,introduce,id,gname,instock,brand from goodslist where id = ? limit ? offset ?", new BeanListHandler<Goods>(Goods.class),cId,pageSize,(currentPage-1)*pageSize);
	}
	@Override
	public int getGoodsCount(Integer cId) throws SQLException {
		
		return runner.query("select count(*) from goodslist where id = ?", new ScalarHandler<Long>(),cId).intValue();
	}
	@Override
	public Category getGoodsCategory(Integer cId) throws SQLException {
		
		return runner.query("select id,categoryimgpath,cname,productdescription from categoryinfo where id = ?", new BeanHandler<Category>(Category.class),cId);
	}
	@Override
	public Goods getGoodsInfo(Integer gId) throws SQLException {
		return runner.query("select gid,goodimgpath,price,addimgpath,introduce,id,gname,instock,brand from goodslist where gid = ?", new BeanHandler<Goods>(Goods.class),gId);
	}

}
